export const state = () => ({
    posts: []
})
  
export const mutations = {
    getPost(state, index){
        return state.posts[index]
    },

    addPost(state, post){
        state.posts.unshift(post);//使用unshift方法将新的帖子插入到state.posts数组的开头,确保新帖子成为数组的第一个元素。
        // if(state.posts.length > 5) {//显示前5个
        //     state.posts.length = 5;
        // }
    },

    deletePost(state, post){
        state.posts = state.posts.filter(v => {
            return (post.title !== v.title);
            // return (post.time !== v.time);
        })
        console.log(state.posts)
    },
    // coverPost(state, { title, content, cityName, time }){
    //     const index = state.posts.findIndex(post => post.title === title);
    // },
}